package com.tutor.lzm.function.tutor.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.squareup.picasso.Picasso;
import com.tutor.lzm.R;
import com.tutor.lzm.http.response.TutorRequiresSearchBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by zzgpc on 2017-10-11.
 * 发布历史
 */
public class TutorHistoryAdapter extends BaseAdapter {
    private List<TutorRequiresSearchBean> tutorList = new ArrayList<>();
    private Context context;

    public TutorHistoryAdapter(Context context, List<TutorRequiresSearchBean> tutorList) {
        this.context = context;
        this.tutorList = tutorList;
    }

    @Override
    public int getCount() {
        return tutorList.size();
    }

    @Override
    public Object getItem(int position) {
        return tutorList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_tutor_history, null);
            viewHolder = new ViewHolder();

            viewHolder.imgSubject = (ImageView) convertView.findViewById(R.id.img_subject);
            viewHolder.tvTutor = (TextView) convertView.findViewById(R.id.tv_tutor);
            viewHolder.tvDate = (TextView) convertView.findViewById(R.id.tv_date);
            viewHolder.tvStatus = (TextView) convertView.findViewById(R.id.tv_status);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        TutorRequiresSearchBean bean = tutorList.get(position);
        Picasso.with(context).load(bean.categoryImageText).error(R.mipmap.subject_math).into(viewHolder.imgSubject);
        viewHolder.tvTutor.setText("需" + bean.gradeIdText + bean.categoryIdText + "家教");
        viewHolder.tvDate.setText(bean.createDate);
        if (bean.status == 0) {
            viewHolder.tvStatus.setText("发布中");
            viewHolder.tvStatus.setTextColor(context.getResources().getColor(R.color.blue_text));

        } else if (bean.status == 1) {
            viewHolder.tvStatus.setText("已关闭");
            viewHolder.tvStatus.setTextColor(context.getResources().getColor(R.color.gray_audit));

        }

        return convertView;
    }

    class ViewHolder {
        ImageView imgSubject;
        TextView tvTutor;
        TextView tvDate;
        TextView tvStatus;
    }
}
